package com.ruoyi.peopleinfo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.peopleinfo.domain.PeopleHistory;
import com.ruoyi.peopleinfo.service.IPeopleHistoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 就诊历史Controller
 * 
 * @author y
 * @date 2022-03-03
 */
@RestController
@RequestMapping("/peopleinfo/history")
public class PeopleHistoryController extends BaseController
{
    @Autowired
    private IPeopleHistoryService peopleHistoryService;

    /**
     * 查询就诊历史列表
     */
    @PreAuthorize("@ss.hasPermi('peopleinfo:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(PeopleHistory peopleHistory)
    {
        startPage();
        List<PeopleHistory> list = peopleHistoryService.selectPeopleHistoryList(peopleHistory);
        return getDataTable(list);
    }

    /**
     * 导出就诊历史列表
     */
    @PreAuthorize("@ss.hasPermi('peopleinfo:history:export')")
    @Log(title = "就诊历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PeopleHistory peopleHistory)
    {
        List<PeopleHistory> list = peopleHistoryService.selectPeopleHistoryList(peopleHistory);
        ExcelUtil<PeopleHistory> util = new ExcelUtil<PeopleHistory>(PeopleHistory.class);
        util.exportExcel(response, list, "就诊历史数据");
    }

    /**
     * 获取就诊历史详细信息
     */
    @PreAuthorize("@ss.hasPermi('peopleinfo:history:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(peopleHistoryService.selectPeopleHistoryById(id));
    }

    /**
     * 新增就诊历史
     */
    @PreAuthorize("@ss.hasPermi('peopleinfo:history:add')")
    @Log(title = "就诊历史", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PeopleHistory peopleHistory)
    {
        return toAjax(peopleHistoryService.insertPeopleHistory(peopleHistory));
    }

    /**
     * 修改就诊历史
     */
    @PreAuthorize("@ss.hasPermi('peopleinfo:history:edit')")
    @Log(title = "就诊历史", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PeopleHistory peopleHistory)
    {
        return toAjax(peopleHistoryService.updatePeopleHistory(peopleHistory));
    }

    /**
     * 删除就诊历史
     */
    @PreAuthorize("@ss.hasPermi('peopleinfo:history:remove')")
    @Log(title = "就诊历史", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(peopleHistoryService.deletePeopleHistoryByIds(ids));
    }
}
